

<template tag="以下文档内容为hycli自动生成">
  <el-dialog
    v-model="conf.visible"
    v-if="conf.visible" 
    :title="title"
    :width="conf.width"
    draggable
    align-center="true"
    :close-on-click-modal="false"
  >
<el-form :model="form"  ref="form" :rules="rules_aaatp">
    <el-row>
    <el-col :span="24">
    <!-- {"index":54,"raw":"name","name":"name","cname":"Name","type":{"raw":"varchar(48)","name":"varchar","len":48,"dlen":0},"defValue":"","allowNull":false,"constraints":["q","l","le","c","u","rows(1)","v","DN","#like","ps(full)"],"desc":{"raw":"角色名称","name":"角色名称"}} -->
    <!--角色名称 输入控件 -->
    <el-form-item prop="name" label="角色名称" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.name"  maxlength="48" 
      :rows="1"  placeholder="请输入角色名称"  />
      </el-form-item>
    </el-col>
    <el-col :span="24">
    <!-- {"index":56,"raw":"data_authority","name":"data_authority","cname":"DataAuthority","type":{"raw":"varchar(48)","name":"varchar","len":48,"dlen":0},"defValue":"","allowNull":true,"constraints":["q","l","le","c","u","v","sl(my_business_line)","tp(multicheck,c-u)","ps(full)"],"desc":{"raw":"数据权限","name":"数据权限"}} -->
    <!--数据权限 chckbox-group -->
    <el-form-item prop="data_authority" label="数据权限" label-width="100px" label-position="right">
      <el-checkbox-group v-model="form.data_authority"  >
      <el-checkbox-button v-for="item in data_authorityList" :key="item.value" :label="item.value"  :value="item.value">
        {{item.name}}
        </el-checkbox-button>
      </el-checkbox-group>
      </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":57,"raw":"status","name":"status","cname":"Status","type":{"raw":"tinyint(1)","name":"tinyint","len":1,"dlen":0},"defValue":"0","allowNull":false,"constraints":["l","le","c","u","v","sl","tp(radio,c-u)","tp(switch,l)"],"desc":{"raw":"状态 0正常 1禁用","name":"状态"}} -->
    <el-form-item prop="status" label="状态" label-width="100px" label-position="right">
      <el-radio-group v-model="form.status"   >
        <el-radio-button v-for="item in statusList" :key="item.value" :label="item.value" >
            {{item.name}}
        </el-radio-button>
      </el-radio-group>
      <el-tooltip raw-content="true" content="状态 0正常 1禁用" placement="bottom" effect="light">
      <i class="form_item_info fa fa-info-circle"  aria-hidden="true" />
      </el-tooltip>
    </el-form-item>
    </el-col>
    </el-row>
</el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="hide" icon="close">取消</el-button>
        <el-button type="primary" @click="save" icon="select">提交</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import rtext from "@/views/cmpnts/rtext.vue"
export default {
  components: {
    rtext
},
  data() {
    return {
      conf: {
        visible: false,
        width:"60%",
        uploadPath:this.$theia.env.join("/file/upload"),
      },
      title:"修改角色信息",
rules_aaatp:{
    name:[{required:true,message:"请输入角色名称",trigger: 'blur'}],
    data_authority:[{required:false,message:"请输入数据权限",trigger: 'blur'}],
    status:[{required:true,message:"请输入状态",trigger: 'blur'}],
  },
    form:{
        name:"",
        data_authority:[],
        status:"",
    },
    data_authorityList:[],
    statusList:[],
    }
  },
  methods: {
    show(form) {
      this.conf.visible = true;
      this.loadEnums_aaatp()
      this.form = Object.assign(form,this.$route.params)
      this.get(form)
    },
      get(form){
        let that = this
        this.conf.loading = true
        let postForm = {}
        postForm.role_id = form.role_id
        this.$theia.http.get("/sso/role/info",postForm).then(res=>{
          res.data_authority = (res.data_authority+"").split(",")
          that.form = Object.assign(that.form, res)
        //处理枚举重新绑定
          this.loadEnums_aaatp()
          that.conf.loading = false
        }).catch(res=>{
          let code = ((res||{}).response||{}).status||0
          let msg = `角色信息查询失败(${code})`
          that.$notify.error({title: '失败',message:msg ,duration:5000})
        })
    },
    save(){
        this.$refs.form.validate((v=>{
            if(v) this.onSave()
        }))
    },
    onSave(){
      let that = this
        let postForm = Object.assign({},this.form)
        postForm.data_authority = (postForm.data_authority||[]).join(",")
        this.$theia.http.put("/sso/role/info",postForm).then(res=>{
            that.$notify.success({title: '成功',message: '角色信息保存成功',duration:5000})
            that.$theia.enum.clear("role_info")
            that.$theia.enum.get("role_info")
            that.hide()
            that.$emit("onsaved")
        }).catch(res=>{
            let code = ((res||{}).response||{}).status||0
            let msg = `角色信息修改失败(${code})`
            that.$notify.error({title: '失败',message: msg,duration:5000})
        })
    },
    hide() {
      this.conf.visible = false;
      this.$refs.form.resetFields();
    },
     onUploadSuccess(response){
    },
    loadEnums_aaatp(){
        //数据权限
        this.data_authorityList = this.$theia.enum.get("my_business_line","","" ,false,"")
        //状态
        this.statusList = this.$theia.enum.get("status","","" ,false,"")
    },

  },
};
</script>

<style scoped>
.form_item_info{
  margin-left: 4px;
  color:#999;
}
.form_item_info:hover{
  cursor: pointer;
  font-weight: 500;
  color:#333;
}
</style>